#! /bin/sh

cmd=$1

start()
{
    rm -f /dev/scull[0-3]
    insmod scull.ko || exit 1
    echo "[*] insmod scull.ko complete"

    major=`awk '/scull/ {print $1}' /proc/devices`

    mknod -m 666 /dev/scull0 c $major 0
    mknod -m 666 /dev/scull1 c $major 1
    mknod -m 666 /dev/scull2 c $major 2
    mknod -m 666 /dev/scull3 c $major 3

    echo "[*] mknod /dev/scull success, major=$major"
}

stop()
{
    rm -f /dev/scull[0-3] /dev/scull
    echo "[*] remove /dev/scull complete"
    rmmod scull || exit 1
    echo "[*] rmmod scull complete"
}

case "$cmd" in
    "start" )
        echo "[*] start"
        start
        ;;
    "stop" )
        echo "[*] stop"
        stop
        ;;
    "restart" )
        echo "[*] restart"
        stop
        start
        ;;
    *)
        echo "[*] default"
        stop
        start
        ;;
esac
        

